//
// Created by grg on 2020/8/4.
// Copyright (c) 2020 龚任根. All rights reserved.
//

#ifndef TEST_CPP_PROJECT_VIEWGROUP_H
#define TEST_CPP_PROJECT_VIEWGROUP_H


#include "View.h"
#include "List.h"

class ViewGroup : public View {

private:
    List<View> *childs = nullptr;

public:
    ViewGroup(SDL_Rect *initMyRect, SDL_Rect *parentRect, int targetZ)
            : View(initMyRect, parentRect, targetZ) {
        childs = initChildViews();

    }

    ~ViewGroup() {
        if (childs != nullptr) {
            delete childs;
        }
    }

    virtual List<View> *initChildViews() = 0;

    void event(const SDL_Event *event) {
        //调用自己的onEvent
        onEvent(event);

        if (childs != nullptr) {
            //链式子event
            for (int i = 0; i < childs->size(); ++i) {

            }
        }
    }

    void preUpdate() {
        //调用自己的onPreUpdate
        onPreUpdate();

        if (childs != nullptr){
            //链式子preUpdate
            for (int i = 0; i < childs->size(); ++i) {

            }
        }
    }

};


#endif //TEST_CPP_PROJECT_VIEWGROUP_H
